# Maintainer: yms_hi <yms_hi@Outlook.com>
pkgname=('cangjie-beta-bin' 'cangjie-beta-tools-bin' 'cangjie-beta-runtime-bin')
pkgver="0.53.18"
pkgrel=1
epoch=
arch=('x86_64')
pkgdesc='Cangjie(STS Channel)'
url="https://cangjie-lang.cn/"
license=('unknown')
groups=('cangjie-beta-full')
depends=()
makedepends=()
checkdepends=()
provides=()
conflicts=()
replaces=()
backup=()
options=(!strip)
install=
changelog=
source=("Cangjie-$pkgver-windows-amd64.tar.gz::https://cangjie-lang.cn/v1/files/auth/downLoad?nsId=142267&fileName=Cangjie-0.53.18-windows_x64.zip&objectKey=67a2c8a26a75297d1cdc1d4e")
sha256sums=('74080EFA705212C4E494A8C18D40293BED9CE3020EEC357C6A288FA6E6B4D379')
noextract=()
validpgpkeys=()

# build(){
#         cd "$srcdir/cangjie"
#         rm -r ./lib/windows_x86_64_llvm/
#         rm -r ./modules/windows_x86_64_llvm/
# }

package_cangjie-beta-runtime-bin(){
        provides=("cangjie-runtime=$pkgver")
        depends=('openssl>=3.0.7')
        conflicts=('cangjie-runtime')
        pkgdesc='Runtime for Cangjie(Beta Channel)'
        cd "$srcdir/cangjie"
        mkdir -p "$pkgdir/opt/cangjie-beta/runtime/lib/windows_${CARCH}_llvm/"
        mkdir -p "$pkgdir/usr/lib"
        cp -r "./runtime/lib/windows_${CARCH}_llvm/" "$pkgdir/opt/cangjie-beta/runtime/lib/"
        chmod 755 "$pkgdir/opt/cangjie-beta/runtime/lib/windows_${CARCH}_llvm/" -R

        cd "$pkgdir/usr/lib"
        for file in "$pkgdir/opt/cangjie-beta/runtime/lib/windows_${CARCH}_llvm/"/*;
        do
            _link_path=$(basename "$file")
            ln -s "../../opt/cangjie-beta/runtime/lib/windows_${CARCH}_llvm/$_link_path" "./$_link_path"
            chmod 755 "$pkgdir/usr/lib/$_link_path"
        done
}

package_cangjie-beta-bin() {
        pkgdesc="Cangjie compiler(Beta Channel)"
        provides=("cangjie-bin=$pkgver")
        depends=("cangjie-beta-runtime-bin=$pkgver" 'openssl>=3.0.7')
        conflicts=('cangjie-bin')
        cd "$srcdir/cangjie"
        install -d "$pkgdir/opt/cangjie-beta/bin" "$pkgdir/opt/cangjie-beta/lib/" "$pkgdir/opt/cangjie-beta/modules/"
        cp -r './third_party/' "$pkgdir/opt/cangjie-beta"
        cp -r './bin/' "$pkgdir/opt/cangjie-beta"
        cp -r './lib/' "$pkgdir/opt/cangjie-beta"
        cp -r './modules' "$pkgdir/opt/cangjie-beta"
        chmod 755 "$pkgdir/opt/cangjie-beta/" -R
}

package_cangjie-beta-tools-bin(){
        pkgdesc='Tools for Cangjie(Beta Channel)'
        depends=("cangjie-beta-bin=$pkgver")
        provides=("cangjie-tools=$pkgver")
        conflicts=('cangjie-tools')
        cd "$srcdir/cangjie"
        install -d "$pkgdir/opt/cangjie-beta/tools"
        cp -r './tools' "$pkgdir/opt/cangjie-beta/"
        cp './envsetup.'* "$pkgdir/opt/cangjie-beta/"
        chmod 755 "$pkgdir/opt/cangjie-beta/" -R
}
